package com.homestead.service;

import com.homestead.result.RedisLockResult;
import com.homestead.utils.MySupplier;
import com.homestead.utils.RStore;
import org.redisson.api.RLock;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author HanBin_Yang
 * @since 2021/5/23 22:42
 */
public interface RedisService {
    Long decrStock(String keyName, long amount, RStore.DecrMode mode);

    Long decrStock(String keyName, long amount);

    Long incrStock(String keyName, long amount);

    void setStock(String keyName, long amount);

    <V> RedisLockResult<V> executeTryLock(String keyName, int waitTime, int expireTime, TimeUnit timeUnit, MySupplier<V> supplier) throws Exception;

    <V> RedisLockResult<V> executeTryLock(RLock lock, int waitTime, int expireTime, TimeUnit timeUnit, MySupplier<V> supplier) throws Exception;

    <V> V executeLock(String keyName, int expireTime, TimeUnit timeUnit, MySupplier<V> supplier) throws Exception;
}
